package com.jdz.controller.backend;

import com.jdz.common.ServerResponse;
import com.jdz.dao.GroupPrivilegeMapper;
import com.jdz.dao.GroupUserMapper;
import com.jdz.dao.PrivilegeMapper;
import com.jdz.service.IRaceTypeService;
import com.jdz.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;


//因为String等基本对象本身已经重写了hashCode,equals方法
//
//        我们要对其他对象排重，把对象放到Set()里，相同的直接去掉了，对比的时候要重写hashCode() and equals()这两个方法
//
//        在idea不要自己写，在实体类里面：
//        右键/Alt+Insert-->hashCode() and equals()-->选择你需要比较的属性（就是需要什么属性相同就代表这个类相同就选择那几个属性）

/**
 * Created by sun
 **/
//项目类型
@Controller
@RequestMapping("/manage/racetype")
public class RaceTypeManageController {

    @Autowired
    IRaceTypeService iRaceTypeService;
//    @Autowired
//    GroupUserMapper groupUserMapper;
//    @Autowired
//    IUserService iUserService;
//    @Autowired
//    GroupPrivilegeMapper groupPrivilegeMapper;
//    @Autowired
//    PrivilegeMapper privilegeMapper;

    /**
     * 添加项目类型+申报时间
     * @param racetype
     * @param parentId
     * @param startTime
     * @param stopTime
     * @return
     */
    @RequestMapping(value = "add_racetype.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addCategory(String racetype, @RequestParam(value = "parentId",defaultValue = "0") Integer parentId,
                                      String startTime,String stopTime){
        return iRaceTypeService.addRaceType(racetype,parentId,startTime,stopTime);
    }

    /**
     * 设置项目类型+申报时间
     * @param racetypeno
     * @param racetype
     * @return
     */
    @RequestMapping(value = "set_racetype_name.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse setCategoryName(Integer racetypeno, String racetype){
        return iRaceTypeService.updateRaceType(racetypeno,racetype);
    }

    /**
     * 删除项目类型
     * @param racetypeno
     * @return
     */
    @RequestMapping(value = "delete_racetype.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse deleteRaceType(Integer racetypeno){
        return iRaceTypeService.deleteRaceType(racetypeno);
    }


    /**
     * 获取项目类型
     * @param request
     * @param session
     * @param parentId
     * @return
     */
    @RequestMapping(value = "get_raceType.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getChildrenParallelCategory(HttpServletRequest request, HttpSession session, @RequestParam(value = "parentId" ,defaultValue = "0") Integer parentId){

        return iRaceTypeService.getParallelRaceType(parentId);

    }


    /**
     * 获取所有项目类型
     * @param request
     * @param session
     * @return
     */
    @RequestMapping(value = "get_all_raceType.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getAllParallelCategory(HttpServletRequest request, HttpSession session){

        return iRaceTypeService.getAllParallelRaceType();

    }

    /**
     * 开始申报
     * @param request
     * @param session
     * @param racetypenoList
     * @return
     */
    @RequestMapping(value = "startDeclaring.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse startDeclaring(HttpServletRequest request, HttpSession session, @RequestParam(value = "racetypenoList[]")List<Integer> racetypenoList){

        return iRaceTypeService.startDeclaring(racetypenoList);
    }

    /**
     * 关闭申报
     * @param request
     * @param session
     * @param racetypenoList
     * @return
     */
    @RequestMapping(value = "stopDeclaring.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse stopDeclaring(HttpServletRequest request, HttpSession session, @RequestParam(value = "racetypenoList[]")List<Integer> racetypenoList){


        return iRaceTypeService.stopDeclaring(racetypenoList);
    }


    /**
     * 设置开始申报时间
     * @param request
     * @param session
     * @param racetypenoList
     * @return
     */
    @RequestMapping(value = "setStartTime.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse setStartTime(HttpServletRequest request, HttpSession session, @RequestParam(value = "racetypenoList[]") List<Integer> racetypenoList, String startTime){

        return iRaceTypeService.setStartTime(racetypenoList,startTime);
    }

    /**
     * 设置结束申报时间
     * @param request
     * @param session
     * @param racetypenoList
     * @return
     */
    @RequestMapping(value = "setStopTime.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse setStopTime(HttpServletRequest request, HttpSession session, @RequestParam(value = "racetypenoList[]") List<Integer> racetypenoList, String stopTime){


        return iRaceTypeService.setStopTime(racetypenoList,stopTime);
    }

}
